package com.wxxymaker.model.dao;

import com.wxxymaker.model.entity.MarkRecord;
import com.wxxymaker.model.entity.Shop;
import com.wxxymaker.model.entity.Stage;
import com.wxxymaker.model.entity.User;
import com.wxxymaker.service.ShopService;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

public interface MarkRecordDao extends JpaRepository<MarkRecord, Long>, JpaSpecificationExecutor<MarkRecord> {

    MarkRecord findByUserAndShopAndStage(User user, Shop shop, Stage stage);

    long countByUserAndStage(User user, Stage stage);

    @Query(nativeQuery = true, value = "select count(id) from t_mark_record where user_id = :uid and stage_id = :sid")
    long countByUserIdAndStageId(@Param("uid") int uid, @Param("sid") int sid);

    long countByStageAndShopAndStar(Stage stage, Shop shop, Integer star);

    /**
     * 统计指定阶段下的参与人数
     * @param stage 阶段
     */
    long countDistinctByStage(Stage stage);
}
